/**
 * @author 徐楠
 * @date 2022/3/28 13:41
 * @version 1.0
 */

package com.xunan.likou;

public class RotateArray {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        rotate(nums,3);
        for (int num : nums) {
            System.out.println(num);
        }
    }

    public static void rotate(int[] nums, int k) {
        int length = nums.length;
        int[] newArray = new int[length];
        for (int i = 0; i < length; ++i) {
            newArray[(i + k) % length] = nums[i];
        }
        System.arraycopy(newArray, 0, nums, 0, length);
    }

}
